package com.hashcoding.eyes.data.entity;

import java.util.ArrayList;
import java.util.List;

/**
 * UserList
 *
 * @author Maochuan
 * @date 2016-02-18
 */
public class UserList {
    private static UserList inst;

    public static UserList instance() {
        if (inst == null) {
            inst = new UserList();
        }
        return inst;
    }

    private List<User> mList;

    private UserList() {
        mList = new ArrayList<User>();
        initData();
    }

    private void initData() {
        mList.add(new User("mao", "摄影爱好者", "http://img1.touxiang.cn/uploads/20131119/19-073243_870.jpg",
                "我就是我，不一样的烟火", "http://littendomo.sinaapp.com/ins/-tqoLXo7v-.jpg"));
        mList.add(new User("admin", "admin", "http://img1.touxiang.cn/uploads/20131119/19-073243_870.jpg",
                "我就是我，不一样的烟火", "http://littendomo.sinaapp.com/ins/-tqoLXo7v-.jpg"));
        mList.add(new User("test", "test", "http://img1.touxiang.cn/uploads/20131119/19-073243_870.jpg",
                "我就是我，不一样的烟火", "http://littendomo.sinaapp.com/ins/-tqoLXo7v-.jpg"));
    }

    public User get(String userID) throws Exception {
        for (User u : mList) {
            if (u.userID.equals(userID)) {
                return u;
            }
        }
        throw new Exception("userID 不存在");
    }

    public void insert(User u) {
        for (User us : mList) {
            if (us.userID.equals(u.userID)) {
                us.name = u.name;
                us.avatarURL = u.avatarURL;
                us.description = u.description;
                return;
            }
        }
        mList.add(u);
    }
}
